package com.tzxs.pay.main.print.datasource;

import android.app.Application;


import com.tzxs.pay.main.print.model.AllPrintBean;
import com.tzxs.pay.main.print.model.UnsetPrintBean;
import com.tzxs.pay.util.ISharedPreference;
import com.tzxs.pay.util.RetrofitUtil;
import com.tzxs.pay.util.RxUtil;
import com.tzxs.pay.util.netnavigator.NetNavigator;

import java.lang.ref.WeakReference;

public class PrintDataSource {


    private static PrintDataSource INSTANCE;

    private WeakReference<Application> app;

    private ISharedPreference sharedPreference;

    private PrintDataSource(WeakReference<Application> app) {
        this.app = app;
        sharedPreference = ISharedPreference.getInstance(app.get());
    }

    public static PrintDataSource getInstance(Application application) {
        if (INSTANCE == null) {
            synchronized (PrintDataSource.class) {
                INSTANCE = new PrintDataSource(new WeakReference<>(application));
            }
        }
        return INSTANCE;
    }


    //打印所有条件的汇总
    public void printAll(int timeType, String timeStart, String timeEnd,
                         NetNavigator<AllPrintBean> navigator) {
        RxUtil.ioMain(RetrofitUtil.getInstance().apiService.printAll(sharedPreference.getToken(),
                timeType, timeStart, timeEnd), navigator);
    }

    //打印未结算相关
    public void unsetPrint(int timeType, String timeStart, String timeEnd, String print1,
                           String print2, NetNavigator<UnsetPrintBean> navigator) {

        RxUtil.ioMain(RetrofitUtil.getInstance().apiService.unsetPrint(sharedPreference.getToken(),
                timeType, timeStart, timeEnd, print1, print2), navigator);
    }
}
